#include "StdAfx.h"

ShaderUI* Singleton<ShaderUI>::m_instance = 0;

ShaderUI::ShaderUI()
{
	m_red = m_blue = m_green = 0x7F;
	m_dialog = new Dialog(450, 100, 8, 5, "Shader");
	m_dialog->m_visible = false;
	m_dialog->AddText(20, 30, "Factors:");
	m_pTRed = m_dialog->AddText(20, 55, "Red: 1.00");
	m_pTGreen = m_dialog->AddText(20, 75, "Green: 1.00");
	m_pTBlue = m_dialog->AddText(20, 95, "Blue: 1.00");
	m_pRed = m_dialog->AddScrollbar(120, 55, 120, this, &ShaderUI::ScrollBarProc);
	m_pBlue = m_dialog->AddScrollbar(120, 95, 120, this, &ShaderUI::ScrollBarProc);
	m_pGreen = m_dialog->AddScrollbar(120, 75, 120, this, &ShaderUI::ScrollBarProc);
	m_pRed->SetRange(0, 25400);
	m_pBlue->SetRange(0, 25400);
	m_pGreen->SetRange(0, 25400);
	m_pGreen->SetValue(12700);
	m_pRed->SetValue(12700);
	m_pBlue->SetValue(12700);
	//m_pShader = m_dialog->AddCheckbox(this, 20, 115, "Enable shading", &ShaderUI::CheckboxProc);
	sUI.AddElement(m_dialog);
}

void ShaderUI::ScrollBarProc(Scrollbar<ShaderUI>* pBar, ui32 value)
{
	float pct = value / 12700.0f;
	ui32 newVal = ui32(pct * 0x7F);
	char msg[255];

	if(pBar == m_pGreen)
	{
		sprintf_s<255>(msg, "Green: %.02f", pct);
		m_pTGreen->szText = msg;
		m_green = newVal;
	}

	if(pBar == m_pBlue)
	{
		sprintf_s<255>(msg, "Blue: %.02f", pct);
		m_pTBlue->szText = msg;
		m_blue = newVal;
	}

	if(pBar == m_pRed)
	{
		sprintf_s<255>(msg, "Red: %.02f", pct);
		m_pTRed->szText = msg;
		m_red = newVal;
	}
}

void ShaderUI::CheckboxProc(Checkbox<ShaderUI>*, ui32 check)
{
	if(check)
	{
		sSelection.EnableMCCV();
		sChat.AddText("You are in SHADER mode!", -1, 0xFFFF0000);
	}
	else
		sChat.AddText("You are in TERRAIN mode!", -1, 0xFFFF0000);
}